let workTime = 25;
let shortBreak = 5;
let longBreak = 15;
let sessionCount = 0;
let timer;
let isRunning = false;
let isWorkSession = true;
let minutes = workTime;
let seconds = 0;

const minutesDisplay = document.getElementById('minutes');
const secondsDisplay = document.getElementById('seconds');
const sessionCountDisplay = document.getElementById('session-count');

function startTimer() {
    if (!isRunning) {
        isRunning = true;
        timer = setInterval(updateTimer, 1000);
    }
}

function pauseTimer() {
    clearInterval(timer);
    isRunning = false;
}

function resetTimer() {
    clearInterval(timer);
    isRunning = false;
    minutes = isWorkSession ? workTime : shortBreak;
    seconds = 0;
    updateDisplay();
}

function updateTimer() {
    if (seconds === 0) {
        if (minutes === 0) {
            clearInterval(timer);
            isRunning = false;
            sessionCount++;
            sessionCountDisplay.textContent = sessionCount;
            alert('计时结束！');
            resetTimer();
        } else {
            minutes--;
            seconds = 59;
        }
    } else {
        seconds--;
    }
    updateDisplay();
}

function updateDisplay() {
    minutesDisplay.textContent = String(minutes).padStart(2, '0');
    secondsDisplay.textContent = String(seconds).padStart(2, '0');
} 